package com.pfzy.utildemo.activity.record.recording;

import android.app.Activity;
import android.content.Context;

import com.pfzy.lib.config.log.MyLog;
import com.pfzy.utildemo.activity.record.recording.callback.UXMikeCallBack;
import com.pfzy.utildemo.activity.record.recording.permission.UXDRPermission;
import com.pfzy.utildemo.activity.record.recording.record.DriverRecording;

/**
 * 录音管理器
 */
public class UXDRManager {
    private static UXDRManager mInstance;
    private DriverRecording mDriverRecording = new DriverRecording();
    private UXDriverRecodingParams mRecodingParams;

    private UXDRManager() {
    }

    public static UXDRManager getInstance() {
        if (mInstance == null) {
            synchronized (UXDRManager.class) {
                if (mInstance == null) {
                    mInstance = new UXDRManager();
                }
            }
        }
        return mInstance;
    }

    public void initParams(Context context, UXDriverRecodingParams params) {
        if (params == null) {
            throw new RuntimeException("params 不能为空");
        }
        this.mRecodingParams = params;
        this.mDriverRecording.initParams(context, this.mRecodingParams);
    }

    public UXDriverRecodingParams getRecodingParams() {
        return this.mRecodingParams;
    }

    /**
     * 更新订单流程
     */
    public void startRecord(Activity activity) {
        UXDRPermission.requestPermissionMike(activity, new UXMikeCallBack() {
            @Override
            public void noPermission() {
                _logd("没有权限，申请用户拒绝，不录音");
            }

            @Override
            public void noPermission2setting() {
                _logd("没有权限，申请用户去了设置页面，不录音");
            }

            @Override
            public void havePermission() {
                mDriverRecording.startRecord(activity); // 开始录音
            }
        });
    }

    public void stopRecord(Activity activity) {
        mDriverRecording.stopService();
    }

    private void _logd(String msg) {
        MyLog.logd("司机录音 " + msg);
    }

    private void _loge(String msg) {
        MyLog.loge("司机录音 " + msg);
    }
}
